package cn.iocoder.yudao.module.def.dal.mysql.project;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.def.controller.admin.project.vo.ProjectPageReqVO;
import cn.iocoder.yudao.module.def.controller.admin.project.vo.ProjectRespVO;
import cn.iocoder.yudao.module.def.dal.dataobject.common.ProjectYearCountDo;
import cn.iocoder.yudao.module.def.dal.dataobject.project.ProjectDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 工程 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ProjectMapper extends BaseMapperX<ProjectDO> {

    default PageResult<ProjectDO> selectPage(ProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProjectDO>()
//                .eqIfPresent(ProjectDO::getProjectCate, reqVO.getProjectCate())
                .inIfPresent(ProjectDO::getProjectCate, reqVO.getProjectCates())
                .eqIfPresent(ProjectDO::getPca, reqVO.getPca())
                .eqIfPresent(ProjectDO::getProvince, reqVO.getProvince())
                .eqIfPresent(ProjectDO::getCity, reqVO.getCity())
                .eqIfPresent(ProjectDO::getArea, reqVO.getArea())
                .eqIfPresent(ProjectDO::getAddress, reqVO.getAddress())
                .likeIfPresent(ProjectDO::getAssignName, reqVO.getAssignName())
                .eqIfPresent(ProjectDO::getFacilityType, reqVO.getFacilityType())
                .likeIfPresent(ProjectDO::getReformApprovalName, reqVO.getReformApprovalName())
                .eqIfPresent(ProjectDO::getConstructionNature, reqVO.getConstructionNature())
                .eqIfPresent(ProjectDO::getWarZone, reqVO.getWarZone())
                .eqIfPresent(ProjectDO::getSeaBorder, reqVO.getSeaBorder())
                .eqIfPresent(ProjectDO::getLngLat, reqVO.getLngLat())
                .eqIfPresent(ProjectDO::getTerrainCate, reqVO.getTerrainCate())
                .eqIfPresent(ProjectDO::getInvestYear, reqVO.getInvestYear())
                .eqIfPresent(ProjectDO::getInvestTotal, reqVO.getInvestTotal())
                .eqIfPresent(ProjectDO::getInvestCentral, reqVO.getInvestCentral())
                .eqIfPresent(ProjectDO::getInvestLocal, reqVO.getInvestLocal())
                .likeIfPresent(ProjectDO::getUnitName, reqVO.getUnitName())
                .eqIfPresent(ProjectDO::getTaskScale, reqVO.getTaskScale())
                .eqIfPresent(ProjectDO::getBuildScale, reqVO.getBuildScale())
                .eqIfPresent(ProjectDO::getBuildStatus, reqVO.getBuildStatus())
                .eqIfPresent(ProjectDO::getAdjustStatus, reqVO.getAdjustStatus())
                .eqIfPresent(ProjectDO::getAdjustId, reqVO.getAdjustId())
                .betweenIfPresent(ProjectDO::getBidDate, reqVO.getBidDate())
                .betweenIfPresent(ProjectDO::getBeginDate, reqVO.getBeginDate())
                .betweenIfPresent(ProjectDO::getInspectDate, reqVO.getInspectDate())
                .betweenIfPresent(ProjectDO::getFinishDate, reqVO.getFinishDate())
                .betweenIfPresent(ProjectDO::getReportDate, reqVO.getReportDate())
                .eqIfPresent(ProjectDO::getFacilityStatus, reqVO.getFacilityStatus())
                .eqIfPresent(ProjectDO::getReplaceNum, reqVO.getReplaceNum())
                .eqIfPresent(ProjectDO::getReplaceCompany, reqVO.getReplaceCompany())
                .eqIfPresent(ProjectDO::getBuildCompany, reqVO.getBuildCompany())
                .eqIfPresent(ProjectDO::getUseCompanyCate, reqVO.getUseCompanyCate())
                .eqIfPresent(ProjectDO::getUseCompany, reqVO.getUseCompany())
                .eqIfPresent(ProjectDO::getManageCompany, reqVO.getManageCompany())
                .eqIfPresent(ProjectDO::getContructCompany, reqVO.getContructCompany())
                .eqIfPresent(ProjectDO::getSupervisorCompany, reqVO.getSupervisorCompany())
                .eqIfPresent(ProjectDO::getResponsibleMaintainCompany, reqVO.getResponsibleMaintainCompany())
                .eqIfPresent(ProjectDO::getConstructMaintainCompany, reqVO.getConstructMaintainCompany())
                .eqIfPresent(ProjectDO::getConstructEffect, reqVO.getConstructEffect())
                .eqIfPresent(ProjectDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ProjectDO::getOtherExtends, reqVO.getOtherExtends())
                .eqIfPresent(ProjectDO::getImgs, reqVO.getImgs())
                .eqIfPresent(ProjectDO::getVideos, reqVO.getVideos())
                .likeIfPresent(ProjectDO::getActualFacilityName, reqVO.getActualFacilityName())
                .betweenIfPresent(ProjectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProjectDO::getId));
    }

    /**
     * 总体情况数据
     *
     * @param city
     * @return
     */
    List<Map<String, Object>> getOverallSituationNum(@Param("city") String city);

    /**
     * 项目类型统计
     *
     * @return
     */
    List<Map<String, Object>> getProjectTypeNum(@Param("city") String city,
                                                @Param("xmType") String xmType);

    /**
     * 经费投入分布
     *
     * @return
     */
//    @Select("SELECT city, SUM(invest_central) AS invest_central, SUM(invest_local) AS invest_local " +
//            "FROM def_project GROUP BY city")
    List<Map<String, Object>> selectInvestmentsGroupedByCity(String city);

    /**
     * 项目年增长
     *
     * @return
     */

    List<ProjectYearCountDo> selectProjectCountsByCityAndYear(@Param("city") String city,
                                                              @Param("xmType") String xmType);


    List<ProjectYearCountDo> selectZqdlProjectCountsByCityAndYear(@Param("city") String city,
                                                                  @Param("xmType") String xmType);

    /**
     * 项目在建率、项目完工率、资金支付率格式相同
     *
     * @return
     */
    List<Map<String, Object>> selectProjectBuildingCountsByCity(@Param("beginDate") String beginDate, @Param("city") String city);

    List<Map<String, Object>> selectProjectCompletionRateByCity(@Param("beginDate") String beginDate, @Param("city") String city);


    List<Map<String, Object>> selectProjectsWithCategory(@Param("startTime") String starTime, @Param("endTime") String endTime, @Param("city") String city);


    List<Map<String, Object>> getSummaryDataByCity(@Param("cityName") String cityName, @Param("startTime") String starTime, @Param("endTime") String endTime);

    List<Map<String, Object>> getSummaryDataByArea(@Param("areaName") String areaName, @Param("startTime") String starTime, @Param("endTime") String endTime);

    List<Map<String, Object>> getProjectCate(@Param("pcode") String pcode);

    List<Map<String, Object>> selectProjectsIndex(@Param("projectCates") String[] projectCates,
                                                  @Param("years") List<String> years,
                                                  @Param("keyword") String keyword,
                                                  @Param("sydw") String[] sydw,
                                                  @Param("jsqy") String[] jsqy,
                                                  @Param("jsdw") String[] jsdw,
                                                  @Param("startYear") String startYear,
                                                  @Param("endYear") String endYear,
                                                  @Param("jsqyArea") String[] jsqyArea);

    Map<String, Object> selectByDataId(@Param("id") Integer id);

    List<Map<String, Object>> selectPaymentRateByCityAndYear(
            @Param("city") String city,
            @Param("yearTime") String yearTime
    );

    List<Map<String, Object>> getArea();

    List<Map<String, Object>> getUseCompany();

    List<Map<String, Object>> getBuildCompany();

    List<ProjectRespVO> getProjectList(ProjectPageReqVO reqVO);

    List<Map<String, Object>> getDeviceNum(@Param("xmType") String xmType, @Param("city") String city);
}